package com.bot.common.chainbo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;

import java.util.Date;

@Data
public class TradingResultsInfo {

    @JsonProperty("data")
    private Data data;

@lombok.Data
    public static class Data {
        @JsonProperty("module")
        private Integer module;

        @JsonProperty("operation")
        private Integer operation;

        @JsonProperty("tx_hash")
        private String txHash;

        @JsonProperty("status")
        private Integer status;

        @JsonProperty("message")
        private String message;

        @JsonProperty("block_height")
        private Long blockHeight;

        @JsonProperty("timestamp")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        private Date timestamp;

        @JsonProperty("nft")
        private Nft nft;

        // getter & setter...
        @lombok.Data
        public static class Nft {
            @JsonProperty("class_id")
            private String classId;

            @JsonProperty("id")
            private String id;

        }
    }

    // 使用Jackson进行转换
    public static TradingResultsInfo fromJson(String json) {
        ObjectMapper mapper = new ObjectMapper();

        try {
            return mapper.readValue(json, TradingResultsInfo.class);
        } catch (JsonProcessingException e) {
            throw new RuntimeException("Failed to parse JSON into TradingResultsVo", e);
        }
    }

}